package com.liang.design;

import com.alibaba.fastjson.JSON;
import com.liang.design.impl.InsideOrderService;
import com.liang.design.impl.POPOrderAdapterService;
import org.itstack.demo.design.mq.OrderMq;
import org.itstack.demo.design.mq.create_account;
import org.junit.Test;

import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.HashMap;

/**
 * @author lsm
 * @ClassName test_MQAdapter.java
 * @Description TODO
 * @createTime 2023年12月03日 20:30:00
 */
public class test_MQAdapter {

    @Test
    public void test_MQAdapter() throws NoSuchMethodException,
            IllegalAccessException, InvocationTargetException {
        create_account create_account = new create_account();
        create_account.setNumber("100001");
        create_account.setAddress("河北北省.廊坊市.⼴广阳区.⼤大学⾥里里职业技术学院");
        create_account.setAccountDate(new Date());
        create_account.setDesc("在校开户");
        HashMap<String, String> link01 = new HashMap<String, String>();
        link01.put("userId", "number");
        link01.put("bizId", "number");
        link01.put("bizTime", "accountDate");
        link01.put("desc", "desc");
        RebateInfo rebateInfo01 = MQAdapter.filter(create_account.toString(),
                link01);
        System.out.println("mq.create_account(适配前)" +
                create_account.toString());
        System.out.println("mq.create_account(适配后)" +
                JSON.toJSONString(rebateInfo01));
        System.out.println("");
        OrderMq orderMq = new OrderMq();
        orderMq.setUid("100001");
        orderMq.setSku("10928092093111123");
        orderMq.setOrderId("100000890193847111");
        orderMq.setCreateOrderTime(new Date());
        HashMap<String, String> link02 = new HashMap<String, String>();
        link02.put("userId", "uid");
        link02.put("bizId", "orderId");
        link02.put("bizTime", "createOrderTime");
        RebateInfo rebateInfo02 = MQAdapter.filter(orderMq.toString(),
                link02);
        System.out.println("mq.orderMq(适配前)" + orderMq.toString());
        System.out.println("mq.orderMq(适配后)" +
                JSON.toJSONString(rebateInfo02));

    }

    @Test
    public void test_itfAdapter() {
        OrderAdapterService popOrderAdapterService = new
                POPOrderAdapterService();
        System.out.println("判断⾸首单，接⼝口适配(POP)： " +
                popOrderAdapterService.isFirst("100001"));
        OrderAdapterService insideOrderService = new InsideOrderService();
        System.out.println("判断⾸首单，接⼝口适配(⾃自营)： " +
                insideOrderService.isFirst("100001"));
    }
}
